# ---------------------------------------------------------------------------
# Author: jachymko
# Desc:   Common appearance settings
# Date:   Dec 23, 2006
# Site:   http://www.codeplex.com/PowerShellCX
# Usage:  In your profile place the following commands:
#  
#         . "$Env:PscxHome\Profile\EyeCandy.ps1"
# ---------------------------------------------------------------------------

function Start-EyeCandy {

	if($PscxForeColor) {
		$Host.UI.RawUI.ForegroundColor = $PscxForeColor
	}
	
	if($PscxBackColor) {
		$Host.UI.RawUI.BackgroundColor = $PscxBackColor
		
		if($Host.Name -eq 'ConsoleHost') {
			$Host.PrivateData.ErrorBackgroundColor   = $PscxBackColor
			$Host.PrivateData.WarningBackgroundColor = $PscxBackColor
			$Host.PrivateData.DebugBackgroundColor   = $PscxBackColor
			$Host.PrivateData.VerboseBackgroundColor = $PscxBackColor
		}
	}
		
	if(-not $DebugPreference) {
		Clear-Host
	}

	if($PscxMotDayPreference -is [ScriptBlock]) {
		$Banner = & $PscxMotDayPreference
		
		if($Banner) {
			$Banner | Write-Host -ForegroundColor $PscxPromptColor
		}
	}

	Update-HostTitle
}


#
# Prompt function
# 
# To modify, create $PscxPromptPreference variable.
# For an example, see the EyeCandy.*.ps1 scripts.
#
function Write-Prompt($Id, $Color = $PscxPromptColor) {
	if($Host.UI.RawUI.CursorPosition.X -ne 0) {
		write-host
	}	
	
	$prompt = "PS $(get-location)>"
	
	if($PscxPromptPreference -is [ScriptBlock]) {
		$OFS = ''
		$prompt = "$(& $PscxPromptPreference $Id)"
	}

	if(-not $Color) {
		$Color = $Host.UI.RawUI.ForegroundColor
	}
	
	($prompt) | write-host -NoNewLine -ForegroundColor $Color
}

function Prompt {
	Write-Prompt (1 + (Get-History -Count 1).Id)
	Update-HostTitle

	return ' '
}

#
# Host Title function
#
# Uses the $PscxHostTitlePreference variable.
# For an example, see the EyeCandy.*.ps1 scripts.
#
function Update-HostTitle {
	if($PscxHostTitlePreference -is [ScriptBlock]) {
		$title = & $PscxHostTitlePreference
		if($title) {
			$OFS = ' '
			$Host.UI.RawUI.WindowTitle = "$title"
			
			return
		}
	}
	
	if($PscxHostTitlePreference) {
		$Host.UI.RawUI.WindowTitle = "$PscxHostTitlePreference"
	}
}

Start-EyeCandy